package com.cdream.basic.algorithm.leetcode.removeDuplicate;

/**
 * @author cdream
 * @date 5/9/21
 */
public class Question283 {
    public void moveZeroes(int[] nums) {
        int start = 0; // 从[0,start) 都是非0元素

        // 遍历到第i个元素后，保证[0,i]的所有非0元素都按顺序排列在[0,k）中
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0) {
                nums[start++] = nums[i];
            }
        }
        for (int i = start; i < nums.length; i++) {
            nums[i] = 0;
        }
    }
}
